package com.gec.servlet;

import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.gec.dao.CategoryDao;
import com.gec.dao.ProductDao;
import com.gec.entity.Category;
import com.gec.entity.Product;
import com.gec.service.ProductService;

@WebServlet("/IndexServlet")
public class IndexServlet extends HttpServlet{
	ProductService productServlet = new ProductService();
	private static final long serialVersionUID = 1L;
	
	 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	  	    CategoryDao categoryDao = new CategoryDao();
	  	    List<Category> categoryList = categoryDao.getCategoryList();
	  	    HttpSession session = request.getSession();	//获取session会话对象
	  	    session.setAttribute("categoryList", categoryList);//将查询到的商品分类存入到session会话中
	  	    
	  	    ProductDao productDao = new ProductDao();
	  	    List<Product> hotProductList = productDao.getHotProductList();
	  	    List<Product> newProductList = productDao.getNewProductList();
	  	    
	  	    request.setAttribute("hotProductList", hotProductList);
	  	    request.setAttribute("newProductList", newProductList);
	  	    
	  	    request.getRequestDispatcher("index.jsp").forward(request, response);
	  	}

	
}
